L.ui.view.extend({
	execute: function() {
		var m = new L.cbi.Map('wireless', {
			caption:	L.tr('Wireless configuration')
		});

		var s = m.section(L.cbi.TypedSection, 'wifi-device', {
			caption:	L.tr('WiFi devices')
		});
		
		s.option(L.cbi.CheckboxValue, 'disabled', {
			caption:	L.tr('Disabled')
		});
		
		var ch = s.option(L.cbi.ListValue, 'channel', {
			caption:	L.tr('Channel')
		});

		ch.load = function(sid) {
			this.choices = [ ];
			this.value('0', L.tr('auto'));
			for (var i = 1, f = 2412;  i < 14; i++, f += 5)
				this.value('' + i, i + ' (' + f + ' MHz)');
		};
		
		ch.save = function(sid) {
			var v = this.formvalue(sid);
			if (v == '0')
				L.uci.set('wireless', sid, 'auotch', 2);
			
			else
				L.uci.set('wireless', sid, 'auotch', 0);
			
			L.uci.set('wireless', sid, 'channel', v);
		};
		
		s = m.section(L.cbi.TypedSection, 'wifi-iface', {
			caption:	L.tr('Device interfaces')
		});
		
		s.filter = function(section, parent_sid) {
			return section.ifname == 'ra0';
		};
		
		s.option(L.cbi.InputValue, 'ssid', {
			caption:	L.tr('SSID')
		});
		
		s.option(L.cbi.ListValue, 'encryption', {
			caption:	L.tr('Encryption'),
			initial:	'none'
		})
		.value('none', L.tr('No encryption'))
		.value('psk', L.tr('WPA Personal (PSK)'))
		.value('psk2', L.tr('WPA2 Personal (PSK)'))
		.value('psk-mixed', L.tr('WPA/WPA2 Personal (PSK) mixed'));

		s.option(L.cbi.PasswordValue, 'key', {
			caption:	L.tr('Passphrase'),
			datatype:	'wpakey'
		}).depends('encryption', function(v) {
			return (v != 'none');
		});
		
		return m.insertInto('#map');
	}
});
